package com.htudata.alarm.service;

import java.util.List;

import com.htudata.alarm.dao.AlarmDao;
import com.htudata.alarm.pojo.po.AlarmLevelPO;
import com.htudata.core.util.operation.CollectionsOperationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class AlarmLevelService {

  public static final String DEFAULT_ALARM_LEVEL_COLOR = "#ffffff";
  
  private static int global_normal_level;
  
  @Autowired
  private AlarmDao alarmDao;
  
  @Value("${normal_level}")
  private int normal_level;
  

  public static AlarmLevelPO getAlarmLevelInfo(List<AlarmLevelPO> alarmLevelList, int level) {
    if (!CollectionsOperationUtils.isValidCollection(alarmLevelList))
      return null; 
    for (AlarmLevelPO result : alarmLevelList) {
      if (result.getLevel() == level)
        return result; 
    } 
    return getAlarmLevelInfo(alarmLevelList, global_normal_level);
  }
  
  @Cacheable(value = {"webCache"}, key = "#root.methodName")
  public List<AlarmLevelPO> getAlarmLevelList(String a2) {
    return this.alarmDao.selectAlarmLevelList(this.normal_level);
  }
}
